feat: add invoice tranching (senior/junior) with waterfall repayment and loss allocation (#862) - #1023
Merged
Merged
Conversation
Contributor
|
Thanks for the scope of this, this is solid. |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #862
Summary
Adds senior/junior invoice tranching with waterfall repayment and first-loss
allocation, spanning a new Soroban contract, SDK bindings, indexer aggregation,
and investor/admin frontend surfaces. Junior capital absorbs losses first;
senior capital receives priority repayment up to a time-proportional yield cap.
What's included
Contract (
contracts/tranche/)calculate_waterfall_splitandcalculate_loss_allocationas pure functionswaterfall repayment distribution, and loss allocation
set_tranche_config,open_tranche_for_token) and read views(
get_pool,get_position,get_effective_apy,simulate_waterfall)SDK (
packages/sdk,sdk/)client.tranchenamespace onAsteraClient:deposit,withdraw,getPool,getPosition,getTotals,getEffectiveApy,getInvoiceExposure,simulateWaterfall,setConfigTrancheClientwith real Soroban invocations (replaces the prior stubs)trancheContractIdadded toAsteraConfigIndexer (
indexer/)tranche_apytable: realized return per tranche per token, recomputedfrom fund/repay/default events after each ingest batch
GET /tranches/apyandGET /tranches/:token/apyendpointsFrontend (
frontend/)app/invest/tranches: side-by-side senior/junior cards (target vs.trailing-realized APY from the indexer), risk explainer, live deposit flow
app/portfolio: per-investor tranche-position section, hidden when theinvestor has no tranche exposure
app/admin/tranches: on-chain config editorapp/admin/waterfall-simulation: hypothetical-default simulation toolTesting
end-to-end scenarios)
loss sum invariant, junior-first ordering
takes loss once junior is exhausted
Acceptance criteria
calculate_waterfall_split/calculate_loss_allocationpure + unit +property tested (zero junior balance, exact-threshold, dust/rounding)
junior exhausted
Notes
Merged latest
main(picks up the #864 access-control work); resolvedastera-client.tsandtypes.tsto keep both thetrancheandaccessControlnamespaces.